function saveRole(roleInfo) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'post',
            url: '/amc/sys/base/role/save',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: roleInfo
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function updateRole(roleInfo) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'put',
            url: '/amc/sys/base/role/update',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: roleInfo
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function deleteRoles(roleIds) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'delete',
            url: '/amc/sys/base/role/deletes',
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token},
            data: roleIds
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function searchRolesOfAgency(agencyCode) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/amc/sys/base/role/search/by/'+agencyCode,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function searchRolesOfGroup(groupid) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/amc/sys/base/role/search/group/'+groupid,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}

function searchRolesOfUser(groupId, userId) {
    return new Promise((resolve, reject) => {
        axios({
            method: 'get',
            url: '/amc/sys/base/role/search/user/'+userId+'/'+groupId,
            baseURL: 'http://127.0.0.1:8098',
            headers: {'authorization': layui.data('user').token}
        }).then((response)=>{
            let back = response.data
            resolve(back)
        }).catch(reason => {
            reject(reason)
        })
    });
}